package org.spbsu.apco.server.system;

import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * User: mikpan
 * Date: 12/12/12
 * Time: 4:01 PM
 */
@Service(value =  "SystemService")
public class SystemService implements SystemManager {
    private Map<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
    private Map<String, Runner> runnerMap = new ConcurrentHashMap<String, Runner>();

    @Override
    public Node registerNode(String mac) {
        final Node node = new Node(mac);
        nodeMap.put(mac, node);
        return node;
    }

    @Override
    public Runner registerRunner(String id) {
        final Runner runner = new Runner(id);
        runnerMap.put(id, runner);
        return runner;
    }

    @Override
    public Node getNodeByMac(String mac) {
        return nodeMap.get(mac);
    }

    @Override
    public Runner getRunnerById(String id) {
        return runnerMap.get(id);
    }

    @Override
    public Collection<Runner> getRunners() {
        return runnerMap.values();
    }

    public void addRunner(Runner runner) {
        runnerMap.put(runner.getId(), runner);
    }
}
